#include "volumetool.h"
#include "ui_volumetool.h"
#include <QGraphicsDropShadowEffect>
#include <QPainter>

VolumeTool::VolumeTool(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VolumeTool)
{
    ui->setupUi(this);

    // 设置窗口为弹出式窗口、无边框和标题栏、禁用窗口的阴影效果
    setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);

    // 设置窗口背景为半透明
    setAttribute(Qt::WA_TranslucentBackground);

    // 自定义阴影效果
    QGraphicsDropShadowEffect* shadowEffect = new QGraphicsDropShadowEffect(this);
    shadowEffect->setOffset(0, 0);
    shadowEffect->setColor("#646464");
    shadowEffect->setBlurRadius(10);
    setGraphicsEffect(shadowEffect);

    // 给按钮设置图标
    ui->silenceBtn->setIcon(QIcon(":/images/volumn.png"));
    // 音量的默认大小是20
    ui->outSlider->setGeometry(ui->outSlider->x(), 180 - 36 - 25, ui->outSlider->width(), 20);
    ui->sliderBtn->move(ui->sliderBtn->x(), ui->sliderBtn->y() - ui->outSlider->height() / 2);
    ui->volumeRadio->setText("20%");
}

VolumeTool::~VolumeTool()
{
    delete ui;
}

void VolumeTool::paintEvent(QPaintEvent *event)
{
    (void) event;
    // 1.创建绘图对象
    QPainter painter(this);
    // 2.设置抗锯齿
    painter.setRenderHints(QPainter::Antialiasing, true);

    // 3.设置画笔
    // 没有画笔时: 画出来的图形就没有边框和轮廓线
    painter.setPen(Qt::NoPen);
    // 4.设置画刷颜色
    painter.setBrush(Qt::white);

    // 创建一个三角形
    QPolygon polygon;
    polygon.append(QPoint(30, 300));
    polygon.append(QPoint(70, 300));
    polygon.append(QPoint(50, 320));

    // 绘制三角形
    painter.drawPolygon(polygon);
}
